//
//  ConverRecordVC.m
//  jingdongfang
//
//  Created by MTiMac01 on 2017/7/19.
//  Copyright © 2017年 JiongLiang Li. All rights reserved.
//

#import "ConverRecordVC.h"
#import "ConverRecordCell.h"
#import "EmptyViewFactory.h"
#import "IGChangCoinBillApi.h"

@interface ConverRecordVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong)IGChangCoinBillApi *changCoinBillApi;
@property(nonatomic,strong)NSArray *dataArray;

@end

@implementation ConverRecordVC

#pragma mark -懒加载
-(NSArray *)dataArray{
    if (!_dataArray) {
        _dataArray=[NSArray array];
    }
    return _dataArray;
}
#pragma mark -生命周期
- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.title = @"兑换记录";
    self.title = NSLocalizedString(@"Redeems History", nil);
    
    [self loadTableView];
    self.changCoinBillApi=[[IGChangCoinBillApi alloc]initWithUId:[IGUser getUid]];
    [self dataRequest];

}

-(void)dataRequest{
    @KWeakObj(self)
    [self.changCoinBillApi startWithDecodeClass:[IGChangCoinBillResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [self.tableView ig_endHeaderRefreshing];
        [self.tableView ig_endFooterRefreshing];
        if (responseObject) {
            IGChangCoinBillResp *resp=responseObject;
            IGChangCoinBillModel*model=resp.data;
            selfWeak.dataArray=model.artCoin;
            if (model.artCoin && model.artCoin.count > 0)
            {
                _dataArray=[NSArray arrayWithArray:model.artCoin];
                [self.tableView ig_isHeaderRefreshing ];
            }
            else
            {
                [self.tableView ig_endFooterRefreshingWithNoMoreData];
            }
            [selfWeak.tableView reloadData];
        }
    }];
    
}

- (void)loadTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor c2Color];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"ConverRecordCell" bundle:nil] forCellReuseIdentifier:@"ConverRecordCell"];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
#pragma mark -Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ConverRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ConverRecordCell" forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (!cell)
    {
        cell = [[ConverRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ConverRecordCell"];
    }
    cell.model = _dataArray[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (KSCREENWIDTH - 30) * 0.54 + 20;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [self loadCircleDataWithFirstPage:YES hud:NO];
}

@end
